/*
 * training.h
 *
 *  Created on: Sep 4, 2013
 *      Author: Alan
 */

#ifndef TRAINING_H_
#define TRAINING_H_

#include "jjann.h"
#include "types.h"

#include <string.h>

struct trainingPattern{
	float32* input;
	float32* target;
};

typedef struct trainingPattern trainingPattern_t;

struct trainingData{
	uint32 inputs;
	uint32 outputs;
	uint32 sampleSize;
	trainingPattern_t* samples;
};

typedef struct trainingData trainingData_t;


float32 trainOneEpoch(netdata_t* net, trainingPattern_t *trainingSet, uint32 trainingSetSize);
float32 validate(netdata_t* net, trainingPattern_t *validationSet, uint32 validationSetSize);

float32 trainUntilConvergence(netdata_t* net, trainingPattern_t *trainingSet, uint32 trainingSetSize, trainingPattern_t *validationSet, uint32 validationSetSize, uint32 maxEpochsFromMinimum);
float32 crossValidation(netdata_t* net, trainingPattern_t *trainingSet, uint32 trainingSetSize, uint32 folds);

uint32 incrementalPruning(/*result*/netdata_tp bestNet, float32 epsilon, uint32 maxTrainingCycles,  uint32 maxHiddenNeurons, trainingData_t* trainingData, trainingData_t* validationData, float32 (*huaf)(netdata_tp, float32 x), float32 (*dhuaf)(netdata_tp, float32 x), float32 (*ouaf)(netdata_tp, float32 x), float32 (*douaf)(netdata_tp, float32 x), float32 (*errorComputation)(float32 *output, float32 *target, size_t size), settings_tp settings);

uint8 loadSamples(trainingData_t *td, int8* filename);
void freeSamples(trainingData_t *td);

/////////////////////////////////////////////////////////////////////////
// THE FOLLOWING FUNCTION SHOULD NOT BE CALLED BY THE USERS			   //
////////////////////////////////////////////////////////////////////////

//backprop
void bpComputeDeltaWeights(netdata_tp net, neuron_tp self);
//iRprop+
void irpComputeDeltaWeights(netdata_tp net, neuron_tp self);



#endif /* TRAINING_H_ */
